using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

using Ras2ClassLib.Common.Data;

namespace Ras2ClassLib
{
	public class VinList : IDataItem
	{
		#region Member variables
		private int m_nListID;
		private string m_strListName;
	    private DateTime m_strBeginDate;
		private DateTime m_strEndDate;
		#endregion

		#region Properties
		public int ID
		{
			get { return m_nListID; }
			set { m_nListID = value; }
		}

		public string Name
		{
			get { return m_strListName; }
			set { m_strListName = value; }
		}

		public DateTime Begin
		{
			get { return m_strBeginDate; }
			set { m_strBeginDate = value; }
		}

		public DateTime End
		{
			get { return m_strEndDate; }
			set { m_strEndDate = value; }
		}

		#endregion

		#region Constructors
		public VinList( )
		{
		}

		#endregion

		#region Overridden functions
		public override string ToString()
		{
			return m_strListName;
		}
		#endregion

		#region IDataList implementation
		public void Load( IDataReader reader )
		{
			m_nListID = Convert.ToInt32(reader["ListaID"]);
			m_strListName = reader["ListaNafn"].ToString();
			m_strBeginDate = Convert.ToDateTime(reader["ListiByrjar"]);
			m_strEndDate = Convert.ToDateTime(reader["ListiEndar"]);
		}
		#endregion

		public TableDescription GetTable( )
		{
			ColumnDescription[] columns = 
			{
				new ColumnDescription( "ListaID", this.ID, DbType.Int32, true ),
				new ColumnDescription( "ListaNafn", this.Name, DbType.String ),
				new ColumnDescription( "ListiByrjar", this.Begin, DbType.DateTime ),
				new ColumnDescription( "ListiEndar", this.End, DbType.DateTime )
			};
			return new TableDescription( "Listi", columns );
		}
	}

	public class VinListSorter : IComparer<VinList>
	{
		#region Member variables
		private String m_strOrderBy;
		#endregion

		#region Constructors
		public VinListSorter( String strOrderBy )
		{
			m_strOrderBy = strOrderBy;
		}
		#endregion

		#region IComparer implementation
		public int Compare( VinList x, VinList y )
		{
			switch ( m_strOrderBy )
			{
				case "Name":
					return x.Name.CompareTo( y.Name );
				case "Begin":
					return x.Begin.CompareTo( y.Begin );
				case "End":
					return x.End.CompareTo( y.End );
			}

			return 0;
		}
		#endregion
	}

	public class VinListCollection : DataList<VinList>
	{
		#region Public functions
		public void Sort( String strOrderBy )
		{
			VinListSorter sorter = new VinListSorter( strOrderBy );
			base.Sort( sorter );
		}
		#endregion	
	}
}
